package com.thtfpc.demo;

import com.thtfpc.ssdp.SSDPDevice;
import com.thtfpc.ssdp.SimpleServiceFinder;
import com.thtfpc.utility.InputUtil;

import java.io.IOException;

public class DemoForFinder implements SimpleServiceFinder.SearchCallback {

    SimpleServiceFinder serviceFinder;

    public DemoForFinder() {
        serviceFinder = new SimpleServiceFinder("urn:schemas-upnp-org:device:MediaRenderer:1", this);
    }


    public void start() {
        try {
            serviceFinder.start();
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
    }


    public void stop() {
        try {
            serviceFinder.stop();
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public void onServiceOnlined(SSDPDevice device) {
        System.out.println("onServiceOnline:" + device);
    }

    @Override
    public void onServiceOfflined(SSDPDevice device) {
        System.out.println("onServiceOfflined:" + device);
    }

    public static void main(String args[]) {
        DemoForFinder demo = new DemoForFinder();
        demo.start();
        System.out.println("type \"exit\" for quit.");
        InputUtil.quitFor("exit", new InputUtil.InputListener() {
            @Override
            public void onUserTypeString(String input) {
                System.out.println("type \"exit\" for quit.");
            }
        });
        demo.stop();
    }
}
